#include <iostream>
#include "Objects.h"
#include "math.h"

namespace CameraLib {

Object::Object(float x, float y, float width, float height) {
	m_x = x;
	m_y = y;
	m_width = width;
	m_height = height;
}

Object::Object() {
	m_x = 0;
	m_y = 0;
	m_width = 0;
	m_height = 0;
}

Object::~Object() {
	free(&m_x);
	free(&m_y);
	free(&m_width);
	free(&m_height);
}

float Object::GetAngle() {
	return m_x;
}

float Object::GetDistance() {
	return GetArea() / 10;
}

float Object::GetDistanceFrom(Object oth) {
	return (float) sqrt(((m_x - oth.m_x) * (m_x - oth.m_x)) + 
						((m_y - oth.m_y) * (m_y - oth.m_y)));
}

void Object::print() {
	printf("<Object: x=%f y=%f width=%f height=%f>\n", m_x, m_y, m_width, m_height);
}

Flag::Flag(Object partOne, Object partTwo, MyOrder me, MyOrder them) {
	m_partOne = (&partOne);
	m_partTwo = (&partTwo);
	m_x = (partOne.GetX() + partTwo.GetX()) / 2;
	m_y = (partOne.GetY() + partTwo.GetY()) / 2;
	m_width = (partOne.GetWidth() + partTwo.GetWidth()) / 2;
	m_height = (partOne.GetHeight() + partTwo.GetHeight()) / 2;
	m_me = me;
	m_them = them;
}


Flag::Flag()  {
	m_partOne = new Object(0, 0, 0, 0);
	m_partTwo = new Object(0, 0, 0, 0);
	m_x = (m_partOne->GetX() + m_partTwo->GetX()) / 2;
	m_y = (m_partOne->GetY() + m_partTwo->GetY()) / 2;
	m_width = (m_partOne->GetWidth() + m_partTwo->GetWidth()) / 2;
	m_height = (m_partOne->GetHeight() + m_partTwo->GetHeight()) / 2;
	m_me = PINKGREEN;
	m_them = PINKGREEN;
}



float Flag::GetDistance() {
	float rawD = sqrt((m_partOne->GetX() - m_partTwo->GetX())*(m_partOne->GetX() - m_partTwo->GetX()) +
					  (m_partOne->GetY() - m_partTwo->GetY())*(m_partOne->GetY() - m_partTwo->GetY()));
	float d = -20.25 * rawD + 15.1125;
	return d;
}

void Flag::print() {
	char* rel;
	if (IsFriend()) rel = "+";
	else rel = "-";
	printf("<Flag(%s): x=%f y=%f width=%f height=%f>\n", rel, m_x, m_y, m_width, m_height);
}

}
